package com.asiainfo.iyoga.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.asiainfo.iyoga.DriverManager;
import com.asiainfo.iyoga.model.YearCard;

public class YearCardDAO {
	Connection conn = null;
	
	public YearCardDAO()
	{
		DriverManager manager = new DriverManager();
		conn = manager.getConnection();
	}


	public boolean addCard(YearCard card) {
		//
		PreparedStatement pst = null; 
    	String sql = "insert into yearcard(BUY_TIME, MEMBER_ID) values('"+
    			card.getLoginDate()+"','" + card.getMemberId() +"')";
    	try {
    		pst = conn.prepareStatement(sql);
    		pst.execute(sql);
    	} catch (Exception e) {
    		e.printStackTrace();
    		return false;
    	}     	
    	return true;
	}
	
	
	
	public void close() {
		try{
			this.conn.close();
		} catch(SQLException err) {
			err.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		YearCard card = new YearCard();
		java.util.Date dt = new java.util.Date();
		java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd");
		String date = sdf.format(dt);
		card.setMemberId(1);
		card.setLoginDate(date);
		YearCardDAO yearCardDao = new YearCardDAO();
		yearCardDao.addCard(card);
	}
	
	
}
